//------------------------------------------------------------------------
// Abstract: Define of class INIFileManager
//
// Authoring: XiaoHanxiong
//
// Time: 2014.03.09
//
// Static test:
//
// Version history:
//		Ver_1.0	: 2014.03.09	XiaoHanxiong
//------------------------------------------------------------------------
#ifndef __Library_INIFileManager_h_
#define __Library_INIFileManager_h_

#include "Stdafx.h"

namespace Library
{
	class _LIBRARY INIFileManager
	{
	private:
		// Constructor
		INIFileManager();
		// Destructor
		~INIFileManager();

	/* Type define */
	public:
		typedef string Section;
		typedef string Name;
		typedef string Value;

		typedef map<Name, Value> ININameValueMap;
		typedef map<Section, map<Name, Value>> INIFileDataSet;
		typedef vector<Section> SectionVec;
		typedef vector<Name> NameVec;

	/* Define *.ini file type */
	public:
		struct INIFile
		{
			string m_file_name;
			INIFileDataSet m_data_set;
			char m_access;
			string m_file_path;
		};
	
	/* Private member */
	private:
		// Single model flag
		static bool ms_b_singleton;
		// Data of *.ini file
		static INIFile ms_ini_file;
		// Read const char
		static const char mc_read = 'r';
		// Modify const char
		static const char mc_modify = 'm';
	private:
		// Clear the INIFile struct
		static void ClearINIFile();
		// Get the specific *.ini the absolute path
		static string GetAbsINIPath(string file_name);
		// Analyse and read the *.ini file with access
		static bool AnalyseINIFile(string file_name, const char access);
		// Write the current INIFile comment to the specific file
		static bool WriteINIFile(string file_name = ms_ini_file.m_file_name);
		

	/* Function for read/write *.ini file */
	public:
		// Set the *.ini manager' model(single/multiple)
		static void SetINIFileModel(bool flag_single = true);
		// Read a *.ini file with specific access
		static bool ConstructINIFile(char* file= "config.ini", const char access = 'r');
		// Get the *.ini config value
		static Value GetValue(Section section, Name name);
		// Set the *.ini config value
		static bool SetValue(Section section, Name name, Value value);
		// Get the current *.ini file name
		static string GetCurrentINIFileName();
		// Write the *.ini file back to it's original file
		static bool WriteBackToINIFile();
		// Write the *.ini file to another file
		static bool WriteToOtherINIFile(char* file);
		// Is the specific section exist
		static bool IsSectionExist(Section section);
		// Is the specific section.name exist
		static bool IsNameExist(Section section, Name name);
		// Enum all sections in *.ini file
		static size_t EnumAllSection(SectionVec& section_vec);
		// Enum all section.name in *.ini file
		static size_t EnumAllName(Section section, NameVec& name_vec);

	public:
		// Get a value from specific *.ini file, it do not care the singleton or not
		static Value GetINIFileValue(char* file_name, Section section, Name name);
		// Set a value from specific *.ini file, it do not care the singleton or not
		static bool SetINIFileValue(char* file_name, Section section, Name name, Value value);
	};

}// _Library_

#endif